// Package sys
// @Link  https://github.com/bufanyun/hotgo
// @Copyright  Copyright (c) 2024 HotGo CLI
// @Author  Ms <133814250@qq.com>
// @License  https://github.com/bufanyun/hotgo/blob/master/LICENSE
// @AutoGenerate Version 2.15.7
package store

import (
	"context"
	"hotgo/api/admin/storeproductattr"
	"hotgo/internal/model/input/store"
	"hotgo/internal/service"
)

var (
	StoreProductAttr = cStoreProductAttr{}
)

type cStoreProductAttr struct{}

// List 查看商品属性列表
func (c *cStoreProductAttr) List(ctx context.Context, req *storeproductattr.ListReq) (res *storeproductattr.ListRes, err error) {
	list, totalCount, err := service.SysStoreProductAttr().List(ctx, &req.StoreProductAttrListInp)
	if err != nil {
		return
	}

	if list == nil {
		list = []*store.StoreProductAttrListModel{}
	}

	res = new(storeproductattr.ListRes)
	res.List = list
	res.PageRes.Pack(req, totalCount)
	return
}

// Export 导出商品属性列表
func (c *cStoreProductAttr) Export(ctx context.Context, req *storeproductattr.ExportReq) (res *storeproductattr.ExportRes, err error) {
	err = service.SysStoreProductAttr().Export(ctx, &req.StoreProductAttrListInp)
	return
}

// Edit 更新商品属性
func (c *cStoreProductAttr) Edit(ctx context.Context, req *storeproductattr.EditReq) (res *storeproductattr.EditRes, err error) {
	err = service.SysStoreProductAttr().Edit(ctx, &req.StoreProductAttrEditInp)
	return
}

// View 获取指定商品属性信息
func (c *cStoreProductAttr) View(ctx context.Context, req *storeproductattr.ViewReq) (res *storeproductattr.ViewRes, err error) {
	data, err := service.SysStoreProductAttr().View(ctx, &req.StoreProductAttrViewInp)
	if err != nil {
		return
	}

	res = new(storeproductattr.ViewRes)
	res.StoreProductAttrViewModel = data
	return
}

// Delete 删除商品属性
func (c *cStoreProductAttr) Delete(ctx context.Context, req *storeproductattr.DeleteReq) (res *storeproductattr.DeleteRes, err error) {
	err = service.SysStoreProductAttr().Delete(ctx, &req.StoreProductAttrDeleteInp)
	return
}
